<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="zh-cn">
    <head>
        <!-- Bootstrap -->
        <include file="Include/css" />
        <title>中经汇通-首页</title>
        <link href="__STATICS__/css/admin/index.css" rel="stylesheet">
        <link href="__STATICS__/css/sweet-alert.css" rel="stylesheet">
        <script type="text/javascript" src="__STATICS__/js/sweet-alert.min.js"></script>

    </head>
    <body>
        <include file="Include/nav_top" />
        <div class="container clearfix" id="left_menu_wraper" >
            <include  file="Include/menu_left" />
            <div id="right-content">
                <div id="right-content-inner">
                    <ul class="breadcrumb">
                        <span>您的位置：</span>
                        <li><a href="{:U('CNEPAdmin/Index/index')}">首页</a> </li>
                        <li class="">系统管理</li>
                        <li class="active">角色设置</li>
                    </ul>


                    <div id="message_wraper" style="display: none;"   class="alert alert-info  alert-dismissible" role="alert">

                        关闭按钮
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        内容

                        <strong>温馨提示：</strong> <span id="message" >{$lastsql}</span>
                    </div>
                    <p>
                        <button id="add_look" class="btn btn-orange" type="button" >
                            添加角色
                        </button>
                    </p>

                    <div role="tabpanel">

                        <div class="row clearfix margin10 form-horizontal">
                            <form  name="query" method="POST" >
                                <span class="pull-left ml30 form_bar">查询：</span>
                                <div class="col-md-2">
                                    <input type="text" name="sRoleName" value="{$Think.post.sRoleName}" placeholder=" 角色名称" class="pull-left ml10 form-control" />
                                </div>
                                    <input type="hidden" name="isEnabled" value="{$Think.request.isEnabled}" />
                                <button type="submit" class="pull-left btn btn-default ml20">
                                    搜索
                                </button>
                            </form>

                            <div class="btn-group pull-right clearfix" data-toggle="buttons">
                                <button type="button" onclick="javascript:window.location.href = '{:U('CNEPAdmin/SysAdminRole/roleList/isEnabled/1')}';" class="btn btn-info {$isEnabled == 1 ? 'active':''}" > 已激活</button>
                                <button type="button" onclick="javascript:window.location.href = '{:U('CNEPAdmin/SysAdminRole/roleList/isEnabled/0')}';"  class="btn btn-info {$isEnabled == 0 ? 'active':''}" > 未激活 </button>
                            </div>
                        </div>

                        <table class="table table-striped table_qrcode  table-hover">
                            <!--<caption>标题</caption>-->
                            <thead>
                                <tr class="border">
                                    <th>编号</th>
                                    <th>角色名称</th>
                                    <th>描述</th>
                                    <th>添加时间</th>
                                    <th>是否激活</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <volist name="list" id="vo">
                                    <tr class="qr_tar">
                                        <td>
                                            {$i+$num}
                                        </td>
                                        <td>
                                                {$vo.roleName}
                                        </td>
                                        <td>{$vo.descript}</td>
                                        <td>{$vo.addTime|date="Y/m/d H:i:s",###} </td>
                                        <td>{$vo['isEnabled'] ?  '已激活':'未激活'} </td>
                                        <td data-id="{$vo.roleID}"><a href="javascript:void(0)" class="edit_look" onclick="edit({$vo.roleID},'{$vo.roleName}','{$vo.descript}',{$vo.isEnabled})" >编辑</a> 
                                            /
                                            <a href="javascript:void(0)" class="tar_delete"  >删除</a> 
                                        </td>
                                    </tr>
                                </volist>
                            </tbody>
                        </table>

                        <div class="clearfix s_page pull-right">
                            {$page}
                        </div>

                    </div>

                </div>

            </div>
        </div>

        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel"> </h4>
                    </div>
                    <div class="modal-body">
                        <div id="message_w_alert" style="display: none;" data-id="alert-info"  class="alert alert-info  alert-dismissible" role="alert">

                            <!--关闭按钮-->
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            <!--内容-->

                            <strong>提示：</strong> <span id="message_alert" ></span>
                        </div>
                        
                            <div class="row clearfix">
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        角色名称：
                                    </div>
                                    <div class="col-md-6">
                                        <input id="roleName" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-1 text_warning text_left form_bar">
                                        *
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        角色描述：
                                    </div>
                                    <div class="col-md-6">
                                        <input id="descript" type="text" class="form-control"/>
                                    </div>
                                    <div class="col-md-1 text_warning text_left form_bar">
                                        *
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-2 text_right form_bar">
                                        是否激活：
                                    </div>
                                    <div class="btn-group clearfix" data-toggle="buttons">
                                        <label class="btn btn-warning btn-sm">
                                            <input name="isOk" type="radio" id="isOk_1" autocomplete="off" value="1" > ON
                                        </label>
                                        <label class="btn btn-warning btn-sm">
                                            <input name="isOk" type="radio" id="isOk_0" autocomplete="off" value="0" > OFF
                                        </label>
                                    </div>
                                </div>
                                <input id="roleID" type="hidden" />
                                
                            </div>
                            

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="save" >保存</button>
                    </div>
                </div>
            </div>
        </div>

        <include file="Include/script" />
        <script>
            var reload = false;
            
            /*菜单展开及高亮*/
            $(function () {
                $('.system').addClass('open');
                $('#system2').addClass('active');

                $('#myModal').on('hidden.bs.modal', function (e) {
                    if(reload) {
                        window.location.reload();
                    }
                 });

                $("#add_look").on("click", function () {
                    $("#roleID").val("");
                    $("#roleName").val("");
                    $("#descript").val("");
                    $("#isOk_1").attr("checked",false);
                    $("#isOk_0").attr("checked",false);
                    
                    
                    $("#myModalLabel").html("添加角色");
                    $('#myModal').modal(); // 跳出弹窗
                });
                $(".edit_look").on("click", function () {
                            $("#myModalLabel").html("编辑角色");
                            $('#myModal').modal(); // 跳出弹窗
                });

                $("#save").on("click", function () {
                    if (checkValue()) {
                        var roleName = $.trim($("#roleName").val());
                        var descript = $.trim($("#descript").val());
                        var isOk = $(":radio[name='isOk']:checked").val();
                        var roleID = parseInt($.trim($("#roleID").val()));
                        
                        var ajaxData = {};
                        if(roleID > 0) {
                            ajaxData.roleID = roleID;
                        }
                        ajaxData.roleName = roleName;
                        ajaxData.descript = descript;
                        ajaxData.isEnabled = isOk;
                        ajax_go(ajaxData ,"{:U('CNEPAdmin/SysAdminRole/saveRole')}",true);
                    }
                });
                
                $(".tar_delete").on("click", function () {
                    var self = $(this);
                    swal({   title: "您确定吗?",
                                text: "您将删除此账号！",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "是的，删除",
                                cancelButtonText: "放弃",
                                closeOnConfirm: false
                            },
                            function (isConfirm) {
                                if (isConfirm) {
                                    var ajaxData = {};
                                    ajaxData.roleID = self.closest('td').attr('data-id');
                                    ajax_go(ajaxData ,"{:U('CNEPAdmin/SysAdminRole/deleteRole')}",true);
                                }

                            });


                });

            });
            
            function edit(id,name,desc,isOk) {
                $("#roleID").val(id);
                $("#roleName").val(name);
                $("#descript").val(desc);
                $("#isOk_"+isOk).attr("checked",true);
                $("#isOk_"+isOk).closest("label").addClass("active");
                
            }
            
            function checkValue() {
                var rt = true;
                var msg = '';

                var roleName = $.trim($("#roleName").val());
                var descript = $.trim($("#descript").val());
                var isOk = $(":radio[name='isOk']:checked").val();

                if (roleName.length == 0) {
                    rt = false;
                    msg = "角色名称不能为空";
                    $("#roleName").focus();
                } else if (descript.length == 0) {
                    rt = false;
                    msg = "请输入角色描述";
                    $("#descript").focus();
                } else if(isNaN(parseInt(isOk))) {
                    rt = false;
                    msg = "请选择是否激活";
                    $(":radio[name='isOk']").focus();
                }
                
                if (!rt) {
                    swal(msg,'','warning');
                } else {
                    swal('正在保存...','','warning');
                }
                return rt;
            }
            
        </script>
    </body>
</html>